/**
定时执行任务
 */
package main

import (
	"fmt"
	"time"
)

func main() {
	input := make(chan interface{})
	go func() {
		input <- "Tasks is running ...."
	}()

	schedule(input)
}

func schedule(input chan interface{}) {
	t1 := time.NewTimer(time.Second * 5)
	t2 := time.NewTimer(time.Second * 10)

	for {
		select {
		case msg := <- input:
			fmt.Println(msg)

		case <-t1.C:
			go task(" Task 1[5s timer]")
			t1.Reset(time.Second * 5)

		case <-t2.C:
			go task(" Task 2[10s timer]")
			t2.Reset(time.Second * 10)
		}
	}
}

func task(name string){
	fmt.Println(time.Now(),name , "has executed.")
}